<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Registration Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 400px;
            text-align: center;
        }
        h2 {
            color: #333;
            margin-bottom: 20px;
        }
        input[type="text"], input[type="password"], select {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        input[type="button"] {
            background-color: #4CAF50;
            color: white;
            padding: 14px 20px;
            margin: 8px 0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }
        input[type="button"]:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>注 册</h2>
    <form  method="post">
        <input type="text" name="name" id="name" placeholder="昵称" required>
        <br>
        <input type="text" name="account" id="account" placeholder="账号" required>
        <br>
        <input type="password" name="pwd" id="pwd" placeholder="密码" required>
        <br>
        <select name="role" id="type">
            <option value="1">用户</option>
            <option value="2">企业</option>
        </select>
        <br>
        <input type="button" value="Register" onclick="register()">
    </form>
    <p>已有账号?立即登录 <a href="index.jsp">登 录</a></p>
</div>
</body>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script>

    /**
     * 注册
     */
    function register() {
        //获取输入的昵称
        var name=$("#name").val();
        if(name==null || name=="" || name==undefined){
            alert("昵称不能为空");
            return;
        }
        //获取输入的账号
        var account=$("#account").val();
        if(account==null || account=="" || account==undefined){
            alert("账号不能为空");
            return;
        }
        //获取输入的密码
        var pwd=$("#pwd").val();
        if(pwd==null || pwd=="" || pwd==undefined){
            alert("密码不能为空");
            return;
        }
        //获取登录的类型
        var type=$("#type").val();
        //异步请求
        $.post("<%=request.getContextPath()%>/YonghuServlet?method=register",{"name":name,"account":account,"pwd":pwd,"type":type},function(data){
            if(data.success){
                alert(data.msg);
                location.href="<%=request.getContextPath()%>/index.jsp";
            }else{
                alert(data.msg);
            }
        },"json")

    }
</script>
</html>